package utils

import (
	"strconv"
	"fmt"
	"os"
	"os/exec"
	"bytes"
)

func StrsTnums(strs []string) []int {
	var nums []int
	for _,n := range strs {
		if n != "" {
			if i,err := strconv.Atoi(n); err!=nil {
				fmt.Printf("convert string(%s) to num failed...", n)
			}else {
				nums = append(nums, i)
			}
		}
	}

	return nums
}

func CheckFileIsExist(filename string) bool {
	var exist = true
	if _, err := os.Stat(filename); os.IsNotExist(err) {
		exist = false
	}
	return exist
}

func Check(e error) {
	if e != nil {
		panic(e)
	}
}

func ExecShell(s string) {
	fmt.Println("exec shell => " + s)
	cmd := exec.Command("/bin/bash", "-c", s)
	var out bytes.Buffer

	cmd.Stdout = &out
	err := cmd.Run()
	Check(err)
	fmt.Printf("%s", out.String())
}